<template>
  <el-container class="home_container">
    <!-- 顶部区域 -->
    <el-header>
      <div>
        <img src="../assets/huhuo.jpeg" width="60px" alt="" />
        <span>狐火管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div @click="collapse" class="collapse">|||</div>
        <el-menu :collapse="isCollapse" :collapse-transition="false" router :default-active="activePath">
          <!-- 一级菜单 -->
          <el-submenu :index="item.id + ''" v-for="item in menulist" :key="item.id">
            <template slot="title">
              <i :class="iconObj[item.id]" class="menu_icon"></i>
              <span>{{ item.authName }}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item :index="'/'+it.path" v-for="it in item.children" :key="it.id" @click="activeNav('/'+it.path)">
              <i class="el-icon-menu"></i>
              <span slot="title">{{it.authName}}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main><router-view></router-view></el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      menulist: [],
      iconObj:{
        '125' : 'iconfont icon-yonghu',
        '103' : 'iconfont icon-ic_opt_feature',
        '101' : 'iconfont icon-shangpin',
        '102' : 'iconfont icon-dingdan',
        '145' : 'iconfont icon-shuju'
      },
      // 是否折叠
      isCollapse: false,
      //激活菜单
      activePath: ''
    };
  },
  created() {
    this.getMenuList();
  },
  methods: {
    logout() {
      // 清空token
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    getMenuList() {
      this.$http.get("/menus").then((response) => {
        this.menulist = response.data.data;
      });
    },
    collapse(){
      this.isCollapse = !this.isCollapse;
    },
    activeNav(path){
      this.activePath=path;
    }
  },
};
</script>

<style lang="less" scoped>
.el-header {
  background-image: linear-gradient(120deg, #d4fc79 0%, #96e6a1 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-left: 0;

  > div {
    display: flex;
    align-items: center;
    > span {
      margin-left: 15px;
      font-size: 20px;
    }
  }
}

.el-main {
  background-image: linear-gradient(120deg, #fdfbfb 0%, #ebedee 100%);
}

.el-menu {
  border-right: none;
}

.home_container {
  height: 100%;
}

.menu_icon {
  margin-right: 5px;
}

.collapse {
  background-image: linear-gradient(to top, #cfd9df 0%, #e2ebf0 100%);
  font-size: 10px;
  line-height: 20px;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>
